<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="<c:url value='/css/jquery-ui.css'/> " rel="stylesheet">
<script type="text/javascript"
	src="<c:url value='/js/jquery-1.11.3.min.js'/>"></script>
<script type="text/javascript"
	src="<c:url value='/js/jquery-ui.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/js/layer/layer.js'/>"></script>
<script type="text/javascript">
	function editorsave(e) {
		if (null == e) {
			var url = "<c:url value='/Emp/toEmp'/>";
		} else {
			var url = "<c:url value='/Emp/toEmp?empno='/>" + e;
		}
		layer.open({
			type : 2,
			title : '新增',
			area : [ '470px', '450px' ],
			maxmin : false,
			content : [ url ],
			btn2 : function() {
				layer.closeAll();
			}
		});
	}
	function del(empno) {
		if (confirm("确定要删除吗 ？")) {
			$.ajax({
				type : "post",
				url : "<c:url value='/Emp/removeEmp'/>",
				data : {
					"empno" : empno
				},
				success : function(data) {
					if (data == true) {
						window.location.reload();
					} else {
						console.log(data)
					}
				}
			})
		}
	}
</script>
</head>
<body>
	<form action="<c:url value='/Emp/allEmp?'/>" name="myForm">
		DEPTNO:<input type="text" name="deptno" id="deptno" value="${deptno }"><input
			type="submit" value="搜索"><input type="button" value="新增"
			onclick="editorsave()">
		<table>
			<thead>
				<tr>
					<td>序号</td>
					<td>EMPNO</td>
					<td>ENAME</td>
					<td>JOB</td>
					<td>MGR</td>
					<td>HIREDATE</td>
					<td>SAL</td>
					<td>DEPTNO</td>
					<td>操作</td>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${pageinfo.list }" var="item" varStatus="num">
					<tr>
						<td>${num.index+1 }</td>
						<td>${item.empno }</td>
						<td>${item.ename }</td>
						<td>${item.job }</td>
						<td>${item.mgr }</td>
						<td><fmt:formatDate value="${item.hiredate }"
								pattern="yyyy-MM-dd HH:mm:ss" /></td>
						<td>${item.sal }</td>
						<td>${item.deptno }</td>
						<td><a href="javascript:editorsave('${item.empno }')">编辑</a>|<a
							href="javascript:del('${item.empno}')">删除</a></td>
					</tr>
				</c:forEach>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="5">第${pageinfo.pageNum}/${pageinfo.pages}页
						共${pageinfo.total}条数据<a href="#"
						onclick="first('${pageinfo.navigateFirstPage}')">首页</a>&nbsp;&nbsp;
						<a href="#"
						onclick="previous('${pageinfo.prePage}','${pageinfo.hasPreviousPage}')">上一页</a>&nbsp;&nbsp;
						<a href="#"
						onclick="next('${pageinfo.nextPage}','${pageinfo.hasNextPage}')">下一页</a>&nbsp;&nbsp;
						<a href="#" onclick="last('${pageinfo.navigateLastPage}')">尾页</a>
					</td>
				</tr>
			</tfoot>
		</table>
	</form>
</body>
<script type="text/javascript">
	function first(obj) {
		var currentPage = obj;
		var url = "<c:url value='/Emp/allEmp?currentPage='/>" + currentPage;
		document.all.myForm.method = "post";
		document.all.myForm.action = url;
		document.all.myForm.submit();
	}
	function previous(obj, hasPreviousPage) {
		if ('false' == hasPreviousPage) {
			layer.alert("已经是最前一页了");
		} else {
			var currentPage = obj;
			var url = "<c:url value='/Emp/allEmp?currentPage='/>" + currentPage;
			document.all.myForm.method = "post";
			document.all.myForm.action = url;
			document.all.myForm.submit();
		}
	}
	function next(obj, hasNextPage) {
		if ('false' == hasNextPage) {
			layer.alert("已经是最后一页了");
		} else {
			var currentPage = obj;
			var url = "<c:url value='/Emp/allEmp?currentPage='/>" + currentPage;
			document.all.myForm.method = "post";
			document.all.myForm.action = url;
			document.all.myForm.submit();
		}
	}
	function last(obj, totalPages) {
		var currentPage = obj;
		var url = "<c:url value='/Emp/allEmp?currentPage='/>" + currentPage;
		document.all.myForm.method = "post";
		document.all.myForm.action = url;
		document.all.myForm.submit();
	}
</script>
<script type="text/javascript">
	$(function() {
		$("#").click(function() {
			$.ajax({
				type : "post",
				url : "",
				data : "",
				success : function(data) {

				}
			})
		})
	})
</script>
</html>